package service.serviceImpl;

import dao.TeaDao;
import dao.daoImpl.TeaDaoImpl;
import pojo.PageInfo;
import pojo.Student;
import service.PageService;
import utils.Page;

import java.sql.SQLException;
import java.util.List;

/**
 * @description:实现分页业务逻辑
 * @author:LSD
 * @when:2018/11/24/20:42
 */
public class PageServiceImpl implements PageService {

    TeaDao teaDao = new TeaDaoImpl();

    @Override
    public Page<Student> getStuByPageInfo(String teaId,PageInfo pageInfo) throws SQLException {

        if (pageInfo.getRows() == null || pageInfo.getPage() == null) {
            pageInfo = new PageInfo();
        }

        //计算分页查询从那条开始
        pageInfo.setStart((pageInfo.getPage() - 1) * pageInfo.getRows());

        //查询总记录数
        Integer count = teaDao.findStusById(teaId).size();

        //查询每页数据列表
        List<Student> list = teaDao.findStusByIdIncludePage(teaId,pageInfo);

        //包装分页数据
        Page<Student> page = new Page<Student>(count, pageInfo.getPage(), pageInfo.getRows(), list);

        return page;
    }

}
